import jakarta.mail.*;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;

import java.util.Properties;

public class SendMail {
    public static void main(String[] args) throws Exception {
        String smtp = "smtp.qq.com";
        String username = "690723481@qq.com";
        String password = "nnjybichobdabejh";

        Properties props = new Properties();
        props.put("mail.smtp.host", smtp);
        props.put("mail.smtp.port", "587");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");

        Session session = Session.getDefaultInstance(props, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username,password);
            }
        });

        session.setDebug(true);

        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("690723481@qq.com"));
        message.setRecipients(Message.RecipientType.TO,"690723481@qq.com");
        message.setSubject("Send Email","UTF-8");
        message.setContent("<h1>Hello World!</h1>","text/html");
        Transport.send(message);
    }
}
